<?php
namespace Admin\Controller;

use Common\Controller\AdminBaseController;

/**
 * 后台下注详情控制器
 */
class BetController extends AdminBaseController
{

//下注详情
    public function index()
    {
        $lottry_array = S('lottry_array');
        $type         = S('type_array');

        if ($_GET['c_no']) {
            $condition['c_no'] = $_GET['c_no'];
        }

        if ($_GET['c_id']) {
            $c_id = $_GET['c_id'];
        } else {
            $c_id = 1;
        }
        $condition['c_id'] = $c_id;

        $count = M('Lottery_order')->where($condition)->group('c_no')->count(); // 查询满足要求的总记录数
        $Page  = new \Think\Page($count, 25); // 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show  = $Page->show(); // 分页显示输出
        $list  = M('Lottery_order')->where($condition)->limit($Page->firstRow . ',' . $Page->listRows)->group('c_no')->select();
        foreach ($list as $k => $v) {
            $list[$k]['money'] = M('Lottery_order')->where('c_no=' . $v['c_no'])->group('c_no')->sum('money');
            $list[$k]['win']   = M('Lottery_order')->where('is_winning=2' . ' and c_no=' . $v['c_no'])->group('c_no')->sum('lost_money');
            $list[$k]['lost']  = M('Lottery_order')->where('is_winning=1' . ' and c_no=' . $v['c_no'])->group('c_no')->sum('win_money');

        }

        $this->assign('lottry_array', $lottry_array);
        $this->assign('c_id', $c_id);
        $this->assign('list', $list);
        $this->assign('page', $show);
        $this->display('Lottryodds/bet');
    }
    public function detail()
    {
        $lottry_array      = S('lottry_array');
        $type              = S('type_array');
        $c_id              = 13;
        $condition['c_no'] = $_GET['c_no'];
        $condition['c_id'] = $c_id;

        $list = M('Lottery_order')->where($condition)->group('w_type,t_type')->select();
        foreach ($list as $k => $v) {
            $list[$k]['money'] = M('Lottery_order')->where("c_id=" . $c_id . " and w_type='" . $v['w_type'] . "' and t_type='" . $v['t_type'] . "'")->sum('money');
            if (is_numeric($v['t_type'])) {
                $list[$k]['content'] = $type[$v['t_type']];
            } else {
                $list[$k]['content'] = $type[$v['w_type']][$v['t_type']];
            }

        }

        $this->assign('lottry_array', $lottry_array);
        $this->assign('c_id', $c_id);
        $this->assign('list', $list);
        $this->display('Lottryodds/bet_detail');
    }

    public function baobiao()
    {
        $lottry_array = S('lottry_array');
        $type         = S('type_array');

        if ($_GET['c_id']) {
            $c_id = $_GET['c_id'];
            //print_r($c_id);exit;
        } else {
            $c_id = 1;
        }

        $condition['c_id'] = $c_id;
        $where['c_id']     = $c_id;
        if (!empty($_GET['strtime'])) {
            $strtime = strtotime($_GET['strtime']);

            if (!empty($_GET['endtime'])) {
                $endtime = strtotime($_GET['endtime']);
                if ($endtime == $strtime) {
                    $endtime = $strtime + 86400;
                }
            } else {
                $endtime = $strtime + 86400;
            }
            $sswhere = '  and  add_time BETWEEN ' . $strtime . ' AND ' . $endtime;
            //print_r('is_winning=2'.' and c_id='.$c_id.$sswhere);exit;
        }
        $qstate = $_GET['settle'];
        if (empty($qstate)) {
            $statussql = '  and status=1';
            $qstate    = 1;
        } elseif ($qstate == 2) {
            $statussql = '  and status=0';
        }

        //$list=M('Lottery_order')->where($condition)->select();

        $list_new['cout']  = M('Lottery_order')->where('c_id=' . $c_id . $statussql . $sswhere)->count();
        $list_new['money'] = M('Lottery_order')->where('c_id=' . $c_id . $statussql . $sswhere)->sum('money');
        //和，无效的投注
        $list_new['he'] = M('Lottery_order')->where('is_winning=3' . ' and c_id=' . $c_id . $statussql . $sswhere)->sum('money');

        //平台赔的钱
        $list_new['win'] = M('Lottery_order')->where('is_winning=1' . ' and c_id=' . $c_id . $statussql . $sswhere)->sum('win_money');
        //平台赚的钱

        $list_new['lost'] = M('Lottery_order')->where('is_winning=2' . ' and c_id=' . $c_id . $statussql . $sswhere)->sum('lost_money');
        //下注返水
        $list_new['rebate'] = M('Lottery_order')->where('is_winning=2' . ' and c_id=' . $c_id . $statussql . $sswhere)->sum('rebate');
        $list_new['shui']   = M('dl_fanli')->where('state=1' . ' and c_id=' . $c_id . $sswhere)->sum('money');

        //print_r($list_new);
        $this->assign('lottry_array', $lottry_array);
        $this->assign('c_id', $c_id);
        $this->assign('v', $list_new);
        $this->assign('page', $show);
        $this->assign('settle', $qstate);
        $this->display('Lottryodds/baobiao');
    }

}
